      subroutine output

      use param
      use allocs

#include <global.h>
      include 'geom.h'
      include 'xsec.h'
      include 'setls.h'
      include 'eigv.h'
      include 'sanmjin.h'
      include 'sanm.h'

      character*30 g1,g2,g3,g4,g5,g6,g7
      real(NBF),dimension(2) :: bcoef,sphi

!     fission source & k-eff      
      g1="src.txt"
      open (unit=81,file=g1,status="replace")
      do im=1,ng
        do j=1,tnode
          write(81,*) im,j,src(1,j,im)
        enddo
      enddo

!     node average flux
!     0th moment
      g2="avgflx1.txt"
      open (unit=82,file=g2,status="replace")
      do im=1,ng
        do j=1,tnode
          write(82,*) im,j,avgflx(1,j,im) 
        enddo
      enddo

!     2nd moment
      g3="avgflx2.txt"
      open (unit=83,file=g3,status="replace")
      do im=1,ng
        do j=1,tnode
          write(83,*) im,j,avgflx(2,j,im) 
        enddo
      enddo

      g4="dprob.txt"
      open (unit=84,file=g4,status="replace")
      do im=1,ng
        do j=1,tnode
          write(84,*) im,j,dprob(j,im) 
        enddo
      enddo

      g5="jin.txt"
      open (unit=85,file=g5,status="replace")
      do im=1,ng
        do j=1,tnode
          write(85,*) im,j,jin(1,j,im),jin(2,j,im) 
        enddo
      enddo

#define tempout
#ifdef tempout
!     0th moment      
      do im=1,ng
        g6="coeff0_"//char(im+48)//".dat"
        open(unit=86,file=g6,status="replace")
        do j=1,tnode
!          write(86,*) 'node','cps0','cps1','cps2','cps3','cps4','cch','csh'
          write(86,*) j,tcp01(j,im),tcp11(j,im),tcp21(j,im),tcp31(j,im),tcp41(j,im) &
     ,               tcosa1(j,im),tsinb1(j,im),krt(1,j,im)
        enddo
      enddo

!     2nd moment
      do im=1,ng
        g7="coeff2_"//char(im+48)//".dat"
        open(unit=87,file=g7,status="replace")
        do j=1,tnode
          write(87,*) j,tcp02(j,im),tcp12(j,im),tcp22(j,im),tcp32(j,im),tcp42(j,im) &
     ,               tcosa2(j,im),tsinb2(j,im),krt(2,j,im) 
        enddo
      enddo
#endif

      end subroutine
